package com.edu.exam.enums;

/**
 * 成绩导出格式枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum GradeExportFormat {
    /** Excel文件 */
    EXCEL("EXCEL", "Excel文件"),
    /** CSV文件 */
    CSV("CSV", "CSV文件"),
    /** PDF文件 */
    PDF("PDF", "PDF文件"),
    /** Word文档 */
    WORD("WORD", "Word文档"),
    /** HTML文件 */
    HTML("HTML", "HTML文件"),
    /** XML文件 */
    XML("XML", "XML文件"),
    /** JSON文件 */
    JSON("JSON", "JSON文件"),
    /** 纯文本 */
    TXT("TXT", "纯文本");

    private final String code;
    private final String description;

    GradeExportFormat(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static GradeExportFormat fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("Code cannot be null");
        }
        for (GradeExportFormat format : values()) {
            if (format.getCode().equals(code)) {
                return format;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    public static GradeExportFormat fromDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("Description cannot be null");
        }
        for (GradeExportFormat format : values()) {
            if (format.getDescription().equals(description)) {
                return format;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}
